home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / BevelDialog.cp < prev    next >
Encoding:
Text File  |  1999-07-16  |  4.5 KB  |  173 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        BevelDialog.cp
  3.  
  4.     Contains:    Bevel Button examples dialog.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. //
  28. //    This file implements a simple dialog which shows a myriad of bevel
  29. //    button possibilities. Even with all it shows, it does not show all
  30. //    the possible variations.
  31. //
  32.  
  33. #include <Fonts.h>
  34. #include <Controls.h>
  35. #include "BevelDialog.h"
  36. #include "Appearance.h"
  37. #include "AppearanceHelpers.h"
  38.  
  39. void    HandleBevelDialog( DialogPtr dialog, short itemHit );
  40.  
  41. void    EnableDisableAll( DialogPtr dialog, Boolean enable );
  42. void    SetControlValues( DialogPtr dialog, short value );
  43. void    SetUpBevelDialog( DialogPtr dialog );
  44.  
  45.  
  46. enum {
  47.     kDisableButton        = 1,
  48.     kEnableButton        = 2,
  49.     kOnButton            = 3,
  50.     kOffButton            = 4,
  51.     kMixedButton        = 5,
  52.     kFirstButton         = 6,
  53.     kLastButton         = 32
  54. };
  55.  
  56. BevelDialog::BevelDialog() : BaseDialog( 1001 )
  57. {
  58.     GrafPtr            savePort;
  59.     ControlHandle    control;
  60.     
  61.     if ( fWindow )
  62.     {
  63.         GetPort( &savePort );
  64.         SetPort( fWindow );
  65.         TextFont( applFont );
  66.         TextSize( 10 );
  67.         SetPort( savePort );
  68.  
  69.  
  70.             // This next bit of code sets one of our bevel buttons up to
  71.             // make the text always appear 0 pixels from the edge in an
  72.             // internationalized fashion, i.e. in left-to-right scripts
  73.             // it will be placed starting 0 pixels from the left.
  74.             // In right-to-left scripts it will be 0 pixels in from the
  75.             // right.
  76.             
  77.         GetDialogItemAsControl( fWindow, 18, &control );    
  78.         SetBevelButtonTextAlignment( control, kControlBevelButtonAlignTextFlushLeft, 0 );
  79.         GetDialogItemAsControl( fWindow, 19, &control );    
  80.         SetBevelButtonTextAlignment( control, kControlBevelButtonAlignTextFlushLeft, 0 );
  81.         GetDialogItemAsControl( fWindow, 20, &control );    
  82.         SetBevelButtonTextAlignment( control, kControlBevelButtonAlignTextFlushRight, 0 );
  83.         GetDialogItemAsControl( fWindow, 21, &control );    
  84.         SetBevelButtonTextAlignment( control, kControlBevelButtonAlignTextFlushLeft, 5 );
  85.  
  86.             // This code sets up some of the buttons to align the text
  87.             // and graphics so they fit together side by side (or above
  88.             // each other).
  89.             
  90.         GetDialogItemAsControl( fWindow, 26, &control );
  91.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceToRightOfGraphic );
  92.         GetDialogItemAsControl( fWindow, 27, &control );
  93.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceToLeftOfGraphic );
  94.         GetDialogItemAsControl( fWindow, 28, &control );
  95.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceBelowGraphic );
  96.         GetDialogItemAsControl( fWindow, 29, &control );
  97.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceAboveGraphic );
  98.         GetDialogItemAsControl( fWindow, 30, &control );
  99.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceSysDirection );
  100.         SetBevelButtonGraphicAlignment( control, kControlBevelButtonAlignSysDirection, 0, 0 );
  101.  
  102.         GetDialogItemAsControl( fWindow, 31, &control );
  103.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceToRightOfGraphic );
  104.         SetBevelButtonGraphicAlignment( control, kControlBevelButtonAlignLeft, 2, 0 );
  105.  
  106.         GetDialogItemAsControl( fWindow, 32, &control );
  107.         SetBevelButtonTextPlacement( control, kControlBevelButtonPlaceToLeftOfGraphic );
  108.         SetBevelButtonGraphicAlignment( control, kControlBevelButtonAlignRight, 2, 0 );
  109.  
  110.  
  111.         ShowWindow( fWindow );
  112.     }
  113. }
  114.  
  115. BevelDialog::~BevelDialog()
  116. {
  117. }
  118.  
  119. void
  120. BevelDialog::HandleItemHit( short itemHit )
  121. {
  122.     switch ( itemHit ) {
  123.         case kDisableButton:
  124.             EnableDisableAll( false );
  125.             break;
  126.         
  127.         case kEnableButton:
  128.             EnableDisableAll( true );
  129.             break;
  130.         
  131.         case kOnButton:
  132.             SetControlValues( kControlCheckBoxCheckedValue );
  133.             break;
  134.         
  135.         case kOffButton:
  136.             SetControlValues( kControlCheckBoxUncheckedValue );
  137.             break;
  138.         
  139.         case kMixedButton:
  140.             SetControlValues( kControlCheckBoxMixedValue );
  141.             break;
  142.             
  143.     }
  144. }
  145.  
  146. void
  147. BevelDialog::EnableDisableAll( Boolean enable )
  148. {
  149.     short        theType;
  150.     Handle        theHand;
  151.     Rect        theRect;
  152.     short        i;
  153.     
  154.     for ( i = kFirstButton; i <= kLastButton; i++ ) {
  155.         GetDialogItem( fWindow, i, &theType, &theHand, &theRect );
  156.         HiliteControl( (ControlHandle)theHand, enable ? 0 : kControlInactivePart );
  157.     }
  158. }
  159.  
  160. void
  161. BevelDialog::SetControlValues( short value )
  162. {
  163.     short        theType;
  164.     Handle        theHand;
  165.     Rect        theRect;
  166.     short        i;
  167.     
  168.     for ( i = kFirstButton; i <= kLastButton; i++ ) {
  169.         GetDialogItem( fWindow, i, &theType, &theHand, &theRect );
  170.         SetControlValue( (ControlHandle)theHand, value );
  171.     }
  172. }
  173.